var IndexUtil={};
$(function () {
    $("#leftAccordion").accordion({
        fit: true,
        border: false,
        animate: true
    });

    BaseUtil.doPost("/sys/sysMenu/nav", {}, function (msg, result) {
        console.log(result);
        $.map(result[0]["children"], function (sysMenu) {
            $("#leftAccordion").accordion("add", {
                title: sysMenu["name"],
                content: "<ul id='tree" + sysMenu["menuId"] + "' ></ul>",
            });

            console.log("tree" + sysMenu["menuId"]);
            console.log(sysMenu);
            $("#tree" + sysMenu["menuId"]).tree({
                data: sysMenu["children"],
                lines: false,
                animate: true,
                formatter: function (node) {
                    return node["name"];
                },
                onSelect : function (node) {
                    IndexUtil.addTab(node);
                }
            });
        })
        return false;
    })
});

/**
 *
 * @param params
 */
IndexUtil.addTab = function (params) {
    var tabs = BaseUtil.getJQuery("#center-tabs");
    if(EasyUiUtil.tabExists(tabs, params["name"])) { // 存在，则选中该对象
        EasyUiUtil.selectTab(tabs, params["name"]);
    } else {
        // 不存在  则新增tab
        tabs.tabs("add", {
            id: params["menuId"],
            title: params["name"],
            iconCls: params["icon"],
            iframe:true,
            href: params['url'],
            closable: true
        })
    }
}